﻿#if WINDOWS_PHONE
using System.Windows;
//using System.Windows.Input;
using Microsoft.Phone.Controls;
#elif NETFX_CORE
using Windows.UI.Xaml;
using Windows.UI.Xaml.Input;
#endif
#if WINDOWS_PHONE || NETFX_CORE
namespace Nx.Commands
{
    public class ControlHoldCommandBehavior : CommandBehaviorBase<UIElement>
    {
        public ControlHoldCommandBehavior(UIElement holdableObject)
            : base(holdableObject)
        {
            if (holdableObject == null)
            {
                throw new System.ArgumentNullException("holdableObject");
            }
#if WINDOWS_PHONE            
            var listener = GestureService.GetGestureListener(holdableObject);
            listener.Hold += OnHold;
#elif NETFX_CORE
            holdableObject.Holding += OnHold;
#endif
        }


#if WINDOWS_PHONE
        private void OnHold(object sender, GestureEventArgs e)
        {
            ExecuteCommand();
        }
#elif NETFX_CORE
        private void OnHold(object sender, HoldingRoutedEventArgs e)
        {
            ExecuteCommand();
        }
#endif
    }
}
#endif